﻿namespace MyWebLog.Logic.Services
{
    using DatabaseAbstraction.Interfaces;
    using MyWebLog.Logic.Models;
    using System.Collections.Generic;

    /// <summary>
    /// This service manipulates blog objects
    /// </summary>
    public class BlogService : MyWebLogService
    {
        #region Constructor

        /// <summary>
        /// Constructor for this service
        /// </summary>
        /// <param name="data">
        /// The data service instances for this service to use
        /// </param>
        public BlogService(IDatabaseService data) : base(data) { }

        #endregion

        #region Get

        /// <summary>
        /// Get all blogs for this installation of My WebLog
        /// </summary>
        /// <returns>
        /// A list of all blogs for this installation
        /// </returns>
        public List<Blog> GetAllBlogs()
        {
            var list = new List<Blog>();

            using (var reader = Data.Select("blog.get.all"))
                while (reader.Read())
                    list.Add(new Blog(reader));

            return list;
        }

        #endregion
    }
}